<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
        <!-- <el-form-item label="考试名称" prop="examTitle">
           <el-select v-model="queryParams.examId" placeholder="请选择考试">
            <el-option
              v-for="item in examList"
              :key="item.id"
              :label="item.title"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item> -->
        <el-form-item label="考生身份证" prop="idCard">
          <el-input
            v-model="queryParams.idCard"
            placeholder="请输入考生身份证"
            clearable
          />
        </el-form-item>
        
        
        <el-form-item>
          <el-button type="primary" icon="el-icon-s-grid" size="mini" @click="handleQuery">抽取</el-button>
          <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button> -->
        </el-form-item>
      </el-form>
  
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <!-- <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['system:user:export']"
          >导出</el-button> -->
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="userList" >
        <el-table-column label="考试名称" align="center" prop="examTitle" />
        <el-table-column label="考生" align="center" prop="playerName" />
        <el-table-column label="考生身份证" align="center" prop="idCard" />
        <el-table-column label="考生账号" align="center" prop="studentLoginName" />
        <el-table-column label="工位" align="center" prop="station" />
        <!-- <el-table-column label="顺序" align="center" prop="orderNum" /> -->
        <el-table-column label="开始时间" align="center" prop="startTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="结束时间" align="center" prop="endTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.endTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              @click="handlePrint(scope.row)"
            >打印</el-button>
          </template>
        </el-table-column>
      </el-table>
  
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <div id="printMe" ref="printContent">
        <el-form ref="infoForm" :model="form" :rules="rules" label-width="80px">
          <!-- <el-form-item label="考试名称: " prop="userId">
            <span>{{ info.title }}</span>
          </el-form-item> -->
          <br><br><br><br>
          <center>
            <div style="width: 300px;">
              <span style="font-size: 36px;font-weight: bold;">{{ info.title }}</span>
            </div>
          </center>
          
          <el-form-item label="准考证号: " prop="userId">
            <span style="font-size: 24px;">{{ info.userName }}</span>
          </el-form-item>
          <el-form-item label="考核日期: " prop="userId">
            <span style="font-size: 24px;">{{ info.startTime }}</span>
          </el-form-item>
          <el-form-item label="打印时间: " prop="userId">
            <span style="font-size: 24px;">{{ info.submitTime }}</span>
          </el-form-item>
          <el-form-item label="考核点: " prop="userId">
            <span style="font-size: 24px;">{{ info.place }}</span>
          </el-form-item>
          <el-form-item label="备注: " prop="userId">
            <span style="font-size: 24px;">{{ info.remark }}</span>
          </el-form-item>
          <el-form-item label="考核项目: " prop="userId">
            <el-table
              :data="info.tableData"
              border
              style="width: 100%;font-size: 18px;color: black;">
              <el-table-column
                prop="num"
                label="序号"
                width="50">
              </el-table-column>
              <el-table-column
                prop="subject"
                label="考核项目"
                width="250">
              </el-table-column>
              <el-table-column
                prop="timeSpent"
                label="考试时限"
                >
              </el-table-column>
              <el-table-column
                prop="reportTime"
                label="场次报到时间"
                width="250">
              </el-table-column>
              <el-table-column
                prop="station"
                label="考位编号">
              </el-table-column>
            </el-table>
          </el-form-item>
          <!-- <span>{{ info.userName }}</span><br>
          <span>{{ info.startTime }}</span><br>
          <span>{{ info.submitTime }}</span><br>
          <span>{{ info.place }}</span><br>
          <span>{{ info.remark }}</span><br> -->
          
        </el-form>
      </div>
      
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" @click="startPrint">打 印</el-button> -->
        <el-button type="primary" v-print="printObj">打印</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    </div>
  </template>
  
  <script>
  import { listPickedUser, getUser, getExams, downloadWord } from "@/api/coffee/user";
  
  export default {
    name: "pickposition",
    data() {
      return {
        printObj: {
          id: 'printMe',//id
          popTitle: "标题",//自定义设置标题
        },
        // 遮罩层
        loading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        userList: [],
        examList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          idCard: null,
          examId: null,
          
        },
        // 表单参数
        form: {},
        info: {},
        // 表单校验
        rules: {
        }
      };
    },
    created() {
      // this.getList();
      this.getExamList()
    },
    methods: {
      getExamList(){
        getExams().then(res => {
            console.log("EXAMS:",res)
            this.examList = res.rows
          })
      },
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        listPickedUser(this.queryParams).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.getExamList();
          this.loading = false;
        });
      },
      
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          userId: null,
          examId: null,
          idCard: null,
          station: null,
          orderNum: null,
          startTime: null,
          endTime: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        console.log(this.queryParams)     
        if(this.queryParams.idCard != null){
          this.loading = true;
          setTimeout(()=>{
            this.getList();
            this.loading = false;
          },500)     
        }else{
          this.$modal.msgError("请输入考生身份证")
        }       
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.queryParams= {
          pageNum: 1,
          pageSize: 10,
          idCard: "",
          examId: null,          
        },
        // this.resetForm("queryForm");
        this.handleQuery();
      },
      /** 修改按钮操作 */
      handlePrint(row) {
        
        downloadWord(row.playerId).then(response => {
            console.log("response:",response)
            this.info = response.data
        //   this.form = response.data;
            this.open = true;
            this.title = "信息打印";
        });
      },
      startPrint(){
        this.open = false
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('coffee/management/examUser/export', {
          ...this.queryParams
        }, `user_${new Date().getTime()}.xlsx`)
      }
    }
  };
  </script>
  